package sk.stuba.fiit.foo07.genex.gui;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JComboBox;

public class ProgressbarMouseHandler extends MouseAdapter {

    private int maxDifficultyPoints = 5; // je 5 bodov obtiaznosti
    private int difficultyRangePoint; // "rozsah" jedneho bodu obtiaznosti
    private ProgressCellRenderer difficultyBar;
    private JComboBox difficultyCombo;

    int xMousePosition;
    int remainder;
    int difficulty;
    int offset;

    ProgressbarMouseHandler(ProgressCellRenderer jbar, JComboBox jc) {
        offset = 0;
        difficultyBar = jbar;
        difficultyCombo = jc;
        int width = jbar.getSize().width;
        difficultyRangePoint = width / maxDifficultyPoints;

    }

    ProgressbarMouseHandler(ProgressCellRenderer jbar, JComboBox jc, int off) {
        offset = off;
        difficultyBar = jbar;
        difficultyCombo = jc;
        int width = jbar.getSize().width;
        difficultyRangePoint = width / maxDifficultyPoints;

    }

    @Override
    public void mousePressed(MouseEvent e) {

        xMousePosition = e.getX();
        remainder = xMousePosition % difficultyRangePoint;
        xMousePosition = xMousePosition - remainder;
        difficulty = xMousePosition / difficultyRangePoint;

        difficultyBar.setIntegerValue(difficulty);
        difficultyCombo.setSelectedIndex(difficulty + offset);

    }

    @Override
    public void mouseExited(MouseEvent e) {

        return;
    }
}
